home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / rockridge / java / threads / classes / Producer.java < prev    next >
Encoding:
Text File  |  1995-11-13  |  381 b   |  18 lines

  1. class Producer extends Thread {
  2.     private CubbyHole cubbyhole;
  3.     private int number;
  4.  
  5.     public Producer(CubbyHole c, int number) {
  6.     cubbyhole = c;
  7.     this.number = number;
  8.     }
  9.  
  10.     public void run() {
  11.     for (int i = 0; i < 10; i++) {
  12.         cubbyhole.put(i);
  13.         System.out.println("Producer #" + this.number + " put: " + i);
  14.         sleep((int)(Math.random() * 100));
  15.     }
  16.     }
  17. }
  18.